// OUTDOOR SECTION SCRIPT
//    Section: X = 2, Y = 2

// This is the special encounter script for this town.
// The states INIT_STATE and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

beginoutdoorscript;

variables;

short i,j,k,r1,choice;

body;

beginstate INIT_STATE;
// This state called whenever this section is loaded into memory.
break;

beginstate START_STATE;
// This state is called every turn the party is in this outdoor section. 
break;

beginstate 10;
	if (get_flag(100,0) >= 8)
		set_state_continue(11);
break;

beginstate 11;
	set_state_continue(12);
break;

beginstate 12;
	if (get_flag(222,0) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"Ahead of you are several agents of the Seawyrm, blocking your path. As you get closer, you see that their weapons are out. Clearly, they have no intention of letting you pass.",0);
	add_dialog_str(1,"_Your mission not already done,_ one of them says. _Return, before you come here, have it finish._",0);
	add_dialog_choice(0,"OK.");
	add_dialog_choice(1,"Attack.");
	choice = run_dialog(1);
	if (choice != 1)
		set_flag(222,0,250);
	if (choice == 2)
		set_state_continue(14);
	set_state_continue(13);
break;

beginstate 13;
	block_entry(1);
	set_state_continue(17);
break;

beginstate 14;
	set_flag(100,0,9);
	set_state_continue(16);
break;

beginstate 15;
	create_out_spec_enc(0);
break;

beginstate 16;
	block_entry(1);
	set_state_continue(15);
break;

beginstate 17;
	set_flag(222,0,0);
	set_state_continue(19);
break;

beginstate 18;
	message_dialog("Well, it's done, and it's extremely unlikely to win you any friends around here. Still, there's a task to do.","");
	set_state_continue(20);
break;

beginstate 19;
	set_flag(100,0,9);
break;

beginstate 20;
	set_flag(100,0,10);
	set_state_continue(21);
break;

beginstate 21;
	set_flag(100,9,1);
break;

beginstate 22;
	if (get_flag(100,0) >= 12)
		set_state_continue(25);
	set_state_continue(23);
break;

beginstate 23;
	message_dialog("You pass the checkpoint unhindered.","");
break;

beginstate 24;
	message_dialog("First, you are showered with a rain of arrows. Then, a large group of guards rush down to engage you. In armed conflict.","");
	j = get_selected_pc();
	// Note that if run_select_a_pc hasn't been called then j is -1 and
	//   effect happens on whole party.
	i = 0;
	while (i < 6) {
		if (((j < 0) || (j == i)) && (char_ok(i))) {
			r1 = get_ran(7,1,7);
			damage_char(i,r1 + 0,0);
			}
		i = i + 1;
		}
	set_state_continue(28);
break;

beginstate 25;
	block_entry(1);
	set_state_continue(26);
break;

beginstate 26;
	reset_dialog();
	add_dialog_str(0,"Countless guards block the checkpoint. You can try to attack, but there's really no way that you'll ever get very far.",0);
	add_dialog_choice(0,"OK.");
	add_dialog_choice(1,"Attack.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(24);
break;

beginstate 27;
	message_dialog("The rest of the guards retreat back to the checkpoint. You're still no closer to breaking through.","");
break;

beginstate 28;
	create_out_spec_enc(1);
break;

beginstate 29;
	if (get_flag(250,0) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"The landscape is becoming increasingly rocky. You wonder what this could possibly mean.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(250,0,250);
break;

beginstate 30;
	if (get_flag(30,9) >= 1)
		set_state_continue(31);
break;

beginstate 31;
	if (get_flag(282,3) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"You descend the stony path up to Grendel's cavern. As you reach the place where it begins, Fernow turns to you. On her face is both sadness and relief.",0);
	add_dialog_str(1,"_I have see all that I wish to see. I leave you now, and give you no more hindrance. You have my thanks._",0);
	add_dialog_str(2,"Before you can gather your thoughts for a response, she begins to walk back to the cavern. You try to say something after her, but nothing comes out of your mouth. Then she is gone.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(282,3,250);
	set_state_continue(32);
break;

beginstate 32;
	remove_char_from_party(1702);
break;

beginstate 33;
	if (get_flag(249,9) == 250)
		end();
	set_flag(249,9,250);
	message_dialog("The mountain scenery here is quite pleasant, and a warm south-wind blows through the area.",
	  "Unfortunately, you're not the first ones to find this place, and the native inhabitants don't seem in a mood to share it with you.");
	create_out_spec_enc(2);
break;

beginstate 34;
	reset_dialog();
	add_dialog_str(0,"A small town has been set up by the shore here. Deep in Seawyrm territory, they're not very used to outlanders. You are invited, somewhat stiffly, to an afternoon meal.",0);
	add_dialog_str(1,"The talk is mostly about small matters, with some inquiries about where you've gone. You give the best answers to commoners you can think of, weaving up some fantastic tales for interest.",0);
	add_dialog_str(2,"As you prepare to leave, you are offered the chance to purchase some rations on your way.",0);
	add_dialog_choice(0,"OK.");
	add_dialog_choice(1,"Buy.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(35);
break;

beginstate 35;
	begin_shop_mode("Village Rations","A small town has been set up by the shore here. As you prepare to leave, you are offered the chance to purchase some rations on your way.",9,2,-1);
break;

beginstate 36;
	block_entry(1);
break;

beginstate 37;
	print_str("Pass too narrow.");
break;

